# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=qt6
pkgname=qt6-qtwebengine
pkgver=6.6.1
pkgrel=2
# latest commit of 112-based branch of qtwebengine-chromium
_chromium_commit="d8d7dc06d0423ad9fdcbe23e741c24b560ff97b8"
pkgdesc="Provides support for web applications using the Chromium browser project"
url="https://qt.io/"
# riscv64 unknown current CPU
# s390x blocked by qt6-qtdeclarative
# ppc64le not supported by chromium
# armv7 use of undeclared identifier '__NR_fstatat'
# armhf missing some includes (cstddef/array/algorithm)
arch="all !riscv64 !s390x !ppc64le !armv7 !armhf"
license="LGPL-2.1-only AND LGPL-3.0-only AND GPL-3.0-only AND Qt-GPL-exception-1.0"
depends_dev="
	alsa-lib-dev
	ffmpeg-dev
	icu-dev
	krb5-dev
	lcms2-dev
	libevent-dev
	libvpx-dev>=1.10.0-r1
	libxkbfile-dev
	libxml2-dev
	libxslt-dev
	minizip-dev
	nss-dev
	opus-dev
	pciutils-dev
	pipewire-dev
	pulseaudio-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtpositioning-dev
	qt6-qttools-dev
	qt6-qtwebchannel-dev
	snappy-dev
	"
makedepends="$depends_dev
	bison
	bsd-compat-headers
	cmake
	flex
	gperf
	gzip
	nodejs
	perl
	py3-html5lib
	python3
	samurai
	"
subpackages="$pkgname-dev"
builddir="$srcdir/qtwebengine-${pkgver/_/-}"

# secfixes:
#   6.6.1-r2:
#     - CVE-2023-6510
#   6.6.1-r1:
#     - CVE-2023-6345
#     - CVE-2023-6346
#     - CVE-2023-6347
#   6.6.0-r6:
#     - CVE-2023-5997
#     - CVE-2023-6112
#   6.6.0-r5:
#     - CVE-2023-5996
#   6.6.0-r2:
#     - CVE-2023-5482
#     - CVE-2023-5849
#   6.6.0-r1:
#     - CVE-2023-5218
#     - CVE-2023-5474
#     - CVE-2023-5475
#     - CVE-2023-5476
#     - CVE-2023-5484
#     - CVE-2023-5486
#     - CVE-2023-5487
#     - CVE-2023-45853

source="$pkgname-$pkgver.tar.gz::https://github.com/qt/qtwebengine/archive/refs/tags/v$pkgver.tar.gz
	qtwebengine-chromium-$_chromium_commit.tar.gz::https://github.com/qt/qtwebengine-chromium/archive/$_chromium_commit.tar.gz
	0001-Enable-building-on-musl.patch
	0002-temp-failure-retry.patch
	0003-qt-musl-mallinfo.patch
	0004-qt-musl-resolve.patch
	0006-no-execinfo.patch
	0007-musl-sandbox.patch
	0009-close.patch
	0014-missing-includes.patch
	0015-enable-x86.patch
	aarch64-skia.patch
	chromium-use-alpine-target.patch
	clang16-aescrypto.patch
	gcc13.patch
	lfs64.patch
	no-sandbox-settls.patch
	pipewire-fcntl-call.patch
	systypes.patch
	icu74.patch
	"

prepare() {
	rmdir "$builddir/src/3rdparty"
	mv "$srcdir/qtwebengine-chromium-$_chromium_commit" "$builddir/src/3rdparty"
	mkdir -p "$builddir"/.git "$builddir/src/3rdparty/chromium/.git"

	default_prepare
}

build() {
	export CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -Wno-builtin-macro-redefined -Wno-deprecated-declarations"
	export CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE -Wno-builtin-macro-redefined -Wno-deprecated-declarations"

	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINSTALL_BINDIR=lib/qt6/bin \
		-DINSTALL_DOCDIR=share/doc/qt6 \
		-DINSTALL_ARCHDATADIR=lib/qt6 \
		-DINSTALL_DATADIR=share/qt6 \
		-DINSTALL_INCLUDEDIR=include/qt6 \
		-DINSTALL_MKSPECSDIR=lib/qt6/mkspecs \
		-DINSTALL_EXAMPLESDIR=share/doc/qt6/examples \
		-DQT_FEATURE_webengine_system_alsa=ON \
		-DQT_FEATURE_webengine_system_ffmpeg=ON \
		-DQT_FEATURE_webengine_system_icu=ON \
		-DQT_FEATURE_webengine_system_libevent=ON \
		-DQT_FEATURE_webengine_system_libpci=ON \
		-DQT_FEATURE_webengine_system_libpng=ON \
		-DQT_FEATURE_webengine_system_libwebp=ON \
		-DQT_FEATURE_webengine_system_libxml=ON \
		-DQT_FEATURE_webengine_system_minizip=ON \
		-DQT_FEATURE_webengine_system_opus=ON \
		-DQT_FEATURE_webengine_system_pulseaudio=ON \
		-DQT_FEATURE_webengine_system_zlib=ON \
		-DQT_FEATURE_webengine_proprietary_codecs=ON \
		-DQT_FEATURE_webengine_kerberos=ON \
		-DQT_FEATURE_webengine_webrtc_pipewire=ON
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
3d4056c636c485042319e907da3c7dd0b5a1cae298e8900a996ce9c68dbc6e82ab2145cd2f8ae5f532280b3692e65988b2133d3c0f5f4a3dbf18d17cf0de99e9  qt6-qtwebengine-6.6.1.tar.gz
2a500b36d925a80e8d5de7b3e445267c6575b46be5b1ea064c49d9ea386453de791d559375a44e3fc5c1dda54b90740d43ce930feb7718704f7754369d614387  qtwebengine-chromium-d8d7dc06d0423ad9fdcbe23e741c24b560ff97b8.tar.gz
9a05c07c4616053d247b1200cdd1883e8067babc5ab5bc169ea1599643d120c445fb4db586f5e247e122711f37e148d13fc8a7443d879877d7c82fb1f778db58  0001-Enable-building-on-musl.patch
7b6ed37975c55e5ebc20b9a6207044b6f86102d69caa6fdd457078a7ae242026d3de5537651d3d86497ba18ddd1e97523aa082da4dff703a8a4f618bccd4af57  0002-temp-failure-retry.patch
82433802b2f22391a6321782eae7f60a2a8453b3a73199cfb7a4e7cd3fc7388ef9896651a7a55d0c8ec67bccb9d4b065709e0f48c0eeadda670225c0462590bb  0003-qt-musl-mallinfo.patch
7751e3a2924f2892384d7a7daf3a9a6770cd873570181854de8fcfb8b1a8430808ad8bf2b6218fa89321ce5446f4e076fea66ca1d2790daf862d016a78b38e51  0004-qt-musl-resolve.patch
426adb8634e8489bc5611a005fe647404cc4cbb573ec4a1a1fb1c1b387d8f1e0a78666d529966d439319abcc1aebe14dae1130ecb36b7e1ebc413849eb2d3546  0006-no-execinfo.patch
5603a1f6cf17d201f32eedd3e67f6ea0796477cb047084af8b0bdb08e897bdcbc7cd90770689a8050c846be4cc0ff8b01af6349c70eac13e024aa85e3fc6cb1c  0007-musl-sandbox.patch
27bb84b5f92798d89a05d0e604c4c5bc8477d4ffdc0e8f0b390ca2dec6473cfd7c70b62999077099d2c5cbc03c7bcb9864963c605e726c7737b8e43dc15a884d  0009-close.patch
2394280f55723d5c02bcdae332009e31c85fcef4ee625b61958818ca96f493d831d5aceb93188c9b07f0af68bdaa59c9d1e75bc2e3b2d410ce4e21a2870f379a  0014-missing-includes.patch
526990b86988980133851e0b280f56dd8bcd21c3dea82f9e8a53ce29650cdff3ec50737759997f2bb5449cb26caee92899c42ac5566addb28354937a521c597b  0015-enable-x86.patch
3b97486b0873a17b35c2187557b320069462e0d08ba88af4af7878628dbeeecfe2ab5bcfc7640c8c87c4c30dbac611d4170c25201c4e7971fbd58eed31e4d756  aarch64-skia.patch
35fd16614f3012f4793221983920f85b209abd543331b14d13bf50d23e028fa34756099a3429028d948a825ec97e9dfeb371fd48852d3f3e5de9f3794e03a7f7  chromium-use-alpine-target.patch
4af26d96c73fcf0395a2a2a0535dbc8f4679b958f047b10e73bd8bc6fa4e44d0b6f2528460d7475f419211449ca7538ba29031b060e575a91cd0c636887cff68  clang16-aescrypto.patch
83057708d6deac9141c88637cccaaabef33d9276e9f02e123d7a782ab5cae46073bfcf6bf2aa4c57eca467b6bc3b6416354a5e7352ad38e71cfe5f46ae8d488a  gcc13.patch
cef2bef9b6daac9c2d51e6a3430a6e7ffa21ecec7ce6a2160891db8fd24d32b47237a77a6b6bf1c9f52d7c9a4dadc9d5ea4bffa7da012367882aae8bdd3df926  lfs64.patch
17141b0de8d629fc4a620318965ab7d6099da90de2a7172f7536a0a2dcded1bdc8b004c36c9000e7f03209e3eeee6e2570037174a0ffd8472ebc2e9af8409ff0  no-sandbox-settls.patch
3c3965bf6d7835c0f1744a11675a301639379fac93df7a9b631c029b652d32708f421ca8461595eb58d5e7e886ba5f959ff04436bae204e295d4bfb6f905bd37  pipewire-fcntl-call.patch
3f9268b47bcb03b485e39e49188f85e5943237713bdb1cf00e97b456064345314c02387c135f979a26cf48fc636a5d492ba7ce817741d4651ce404358a35751a  systypes.patch
a0838a594bb29ed41b7d6aa45ccd8f4dfa7df82fd9e8387dbd61d9d4bb97664152710a0b6a183326d21e0ace9362989575ec77b4fc36246aa6f5eee40206173a  icu74.patch
"
